package cn.edu.cqyz.wisdom.controller;

import cn.edu.cqyz.wisdom.entity.R;
import cn.edu.cqyz.wisdom.util.SampleUtil;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import cn.edu.cqyz.wisdom.config.JwtToken;
import cn.edu.cqyz.wisdom.entity.R;
import cn.edu.cqyz.wisdom.entity.Users;
import cn.edu.cqyz.wisdom.service.IUsersService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 * ⽤户表 前端控制器
 * </p>
 *
 * @author CDHong.it
 * @since 2024-12-18
 */
@Slf4j
@RestController
@RequestMapping("/users")
public class UsersController {

    @Autowired
    public IUsersService service;

    @Autowired
    public RedisTemplate redisTemplate;

    /**
     * 发送注册短信验证
     * */
    @GetMapping("/sendSmsRegister")
    public R sendSmsRegister(@RequestParam String tel){
        return service.sendSmsRegister(tel);
    }

    /**
     * 发送登录验证码
     * */
    @GetMapping("/sendSmsLogin")
    public R sendSmsLogin(@RequestParam String tel){
        return service.sendSmsLogin(tel);
    }

    /**
     * 注册账号
     * */
    @PostMapping("/register")
    public R register(@RequestBody Users users){
        return service.register(users);
    }

    /**
     * 账号密码登录
     * */
    @PostMapping("/login")
    public R login(@RequestBody Users users){
        return service.login(users);
    }

    /**
     * 手机验证码登录
     * */
    @PostMapping("/loginCode")
    public R loginCode(@RequestBody Users users){
        return service.loginCode(users);
    }

    /**
     * 解析token
     */
    @GetMapping("/analysisToken")
    public Users analysisToken(HttpServletRequest request, HttpServletResponse response, Object handler) {
        String token = request.getHeader("token");
        return JwtToken.analysisToken(token);
    }

}
